package com.yhn.init.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.init.common.BaseResponse;
import com.yhn.init.common.DeleteRequest;
import com.yhn.init.common.ResultUtils;
import com.yhn.init.model.dto.outboundItems.OutboundItemsAddRequest;
import com.yhn.init.model.dto.outboundItems.OutboundItemsQueryRequest;
import com.yhn.init.model.dto.outboundItems.OutboundItemsUpdateRequest;
import com.yhn.init.model.vo.OutboundItemsVO;
import com.yhn.init.service.OutboundItemsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 出库信息
 *
 * @author yhnyhn123
 * @email 2236751002@qq.com
 * @date 2024-03-08 20:36:42
 */
@RestController
@RequestMapping("/outbounditems")
public class OutboundItemsController {

    @Resource
    private OutboundItemsService outboundItemsService;

    /**
     * 列表,分页
     */
    @GetMapping("/list")
    //@SaCheckPermissions("furniture/outbounditems/list")
    public BaseResponse<Page<OutboundItemsVO>> listByPage(@RequestBody OutboundItemsQueryRequest outboundItemsQueryRequest) {
        Page<OutboundItemsVO> page = outboundItemsService.queryPage(outboundItemsQueryRequest);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    //@SaCheckPermissions("furniture/outbounditems/info")
    public BaseResponse<OutboundItemsVO> getInfoById(@PathVariable("id") Long id) {
        OutboundItemsVO outboundItems = outboundItemsService.getInfoById(id);

        return ResultUtils.success(outboundItems);
    }


    /**
     * 保存
     */
    @PostMapping("/save")
    // @SaCheckPermissions("furniture/outbounditems/save")
    public BaseResponse<Long> save(@RequestBody OutboundItemsAddRequest outboundItemsAddRequest) {
        Long newId = outboundItemsService.saveOutboundItems(outboundItemsAddRequest);

        return ResultUtils.success(newId);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@SaCheckPermissions("furniture/outbounditems/update")
    public BaseResponse<Boolean> update(@RequestBody OutboundItemsUpdateRequest outboundItemsUpdateRequest) {
        boolean result = outboundItemsService.updateOutboundItems(outboundItemsUpdateRequest);

        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    //@SaCheckPermissions("furniture/outbounditems/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        boolean result = outboundItemsService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    //@SaCheckPermissions("furniture/outbounditems/delete")
    public BaseResponse<Boolean> deleteBatch(@RequestBody Long[] ids) {
        boolean result = outboundItemsService.deleteBatchByIds(ids);
        return ResultUtils.success(result);
    }
}
